package com.lm.common.security.handler;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * 认证失败事件处理器
 *
 * @author lm
 * @date 2019/8/26 10:30
 */
public abstract class AbstractAuthenticationFailureEventHandler implements ApplicationListener<AbstractAuthenticationFailureEvent> {

    @Override
    public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
        Authentication authentication = (Authentication) event.getSource();
        AuthenticationException authenticationException = event.getException();

        handle(authentication, authenticationException);
    }

    /**
     * 登录失败
     *
     * @param authentication
     * @param exception
     */
    public abstract void handle(Authentication authentication, AuthenticationException exception);

}
